<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">

<link href="css/table.css" rel="stylesheet" type="text/css" />
<link href="css/excite-bike/jquery-ui-1.8.22.custom.css" rel="stylesheet" type="text/css" />
<script src="js/jquery-1.7.2.min.js"></script>
<script src="js/jquery.MultiFile.pack.js"></script>
<script src="js/jquery.cookie.js"></script>
<script src="js/jquery-ui-1.8.22.custom.min.js"></script>
<script src="js/widgets.js"></script>

<script type="text/javascript">
	/** 存放單身的結構 **/
	var CXML = [{id:77777,cont:[]}];	//檔案來自
	var CDB	= [];
	var trType = [];	//測試結果類型

	function webForward(tpid,mrid) {
		window.open("http://10.144.113.176:8086/SM1I00/");
		for(var k;k<1000000000;k++);
		
		window.open("http://10.144.113.176:8086/SM1I00/SM1I01/createIssueForm.jsp?mrid="+mrid+"&tpid="+tpid);
	}
	
	function SavaBackToDataStructure(sel,cont,tar,isInDB) {
		if (isInDB) {
			if (tar == "propose") {
				CDB[cont].propose = [];	
			} else if (tar == "designer") {
				CDB[cont].designer = [];
			} else if (tar == "designpm") {
				CDB[cont].designpm = [];
			}
			
			tmpSelectedRole = [];
			$("#detail_"+tar+" li").each(function(i){
				var userID = $(this).attr("userID");
				var nickName = $(this).attr("nickName");
				var item = {"userID":userID,"nickName":nickName };
				tmpSelectedRole.push(item);
			});
			if (tar == "propose") {
				CDB[cont].propose = tmpSelectedRole;	
			} else if (tar == "designer") {
				CDB[cont].designer = tmpSelectedRole;
			} else if (tar == "designpm") {
				CDB[cont].designpm = tmpSelectedRole;
			}
			
		} else {
		 	if (tar == "propose") {
				CXML[sel].cont[cont].propose = [];	
			} else if (tar == "designer") {
				CXML[sel].cont[cont].designer = [];
			} else if (tar == "designpm") {
				CXML[sel].cont[cont].designpm = [];
			} 
			
			tmpSelectedRole = [];
			$("#detail_"+tar+" li").each(function(i){
				var userID = $(this).attr("userID");
				var nickName = $(this).attr("nickName");
				var item = {"userID":userID,"nickName":nickName };
				tmpSelectedRole.push(item);
			});
			if (tar == "propose") {
				CXML[sel].cont[cont].propose = tmpSelectedRole;	
			} else if (tar == "designer") {
				CXML[sel].cont[cont].designer = tmpSelectedRole;
			} else if (tar == "designpm") {
				CXML[sel].cont[cont].designpm = tmpSelectedRole;
			}
		}
	}
	
	
	/** 為了double的畫面中，那些可以選人的欄位 **/
	function Click_changeOwner(obj) {
		var tar = $(obj).attr("tar");
		pickAllStaff(tar);
	}
	
	function Click_CreateTC() {
		window.open("CreateTC.html"); 
	}
	
	/** 檢查目前這個測試項目，能否提審測試結果**/	
	function checkIsSubmitTRable(mrid,ver) {
		$("#sub_ver").val(ver);
		$("#sub_mrid").val(mrid);
		/** IsSubmitTRable中同時更新了是否可以提立交的欄位 **/
		$.ajax({
			type : "post",
			url : "IsSubmitTRable",
			data : $("#q_form").serializeArray(),
			dataType : "TEXT",
			success : function(res) {
				if (res==1) {
					$("#"+mrid+"_subTR").removeAttr("disabled");		//可以提交結果	
				} else {
					$("#"+mrid+"_subTR").attr("disabled","disabled");	//不行提交結果
				}
			}
		});
	}
	
	/** 結果登打畫面的第一層 **/
	function napoleon(type) {
		$("#TRlevel_01_body tr").remove();
		$.ajax({
			type : "post",
			url : "GetTRlevel_01_body",
			data : $("#q_form").serializeArray(),
			dataType : "JSON",
			success : function(Result) {
				var tcuid =[];
				var size = Result.size;
				var tpid = $("#sub_tpid").val();
				var mrid = $("#sub_mrid").val();
				$.each(Result.sqlData, function(i, res) {
					$("#sub_ver")[0].value = res.ver;
					var ind= i+1;
					var bgcolor=getbgColor(ind);
					var trSN = res.trSN;
					var tr = "";  //記錄目前的測試結果 
					if (trSN != 0) {
						for(o=0;o<trType.length;o++) {
							if (trType[o].sn == trSN) {
								tr = trType[o].name+ " (" + trType[o].value + ")";
							}
						}
					} else {
						tr ="";
					}
					
					/** 帳礙登打的按鈕 **/
					var but = "";
					if (type == "fill") {
						but = "<td><button type=\"button\" onClick=\"webForward("+tpid+","+mrid+")\" >輸入</button></td>";
					}	
					
					$("#TRlevel_01_body").append("<tr ondblclick=\"caesar('"+res.tcuid+"')\" bgcolor=\""+bgcolor+"\">"+but+"<td class=\"center\">"+ind+"</td><td>"+res.tcName+"</td><td>"+res.tcKeyPoint+"</td><td>"+res.tcResExp+"</td><td id=\""+res.tcuid+"_level01_tr\">"+tr+"</td><td class=\"right\"  id=\""+res.tcuid+"_level01_retenum\" >"+(res.retenum==0?"":res.retenum)+"</td><td class=\"right\">"+res.numKeyPoint+"</td><td id=\""+res.tcuid+"_level01_succnum\" class=\"right\">"+(res.succnum==0?"":res.succnum)+"</td><td id=\""+res.tcuid+"_level01_failnum\" class=\"right\">"+(res.failnum==0?"":res.failnum)+"</td><td id=\""+res.tcuid+"_level01_cantnum\" class=\"right\">"+(res.cantnum==0?"":res.cantnum)+"</td><td id=\""+res.tcuid+"_level01_waitnum\" class=\"right\">"+(res.waitnum==0?"":res.waitnum)+"</td></tr>");
					
					if (tr == "") {
						$("#"+res.tcuid+"_level01_tr").html("未測試 (unattempted)");
					}
					$("#"+res.tcuid+"_level01_tr").attr("tok",trSN);
					
				});
				
				$("#dialog-TRlevel_01").css("visibility", "visible");
			}, error : function(xhr, ajaxOptions, thrownError) {
				alert("出代誌啊!! \n\n"+xhr.status+"\n\n"+xhr.responseText);
			}
		});
	}
	
	/** 產生結果登打畫面 **/
	function caesar(uid) {
		$("#tr_edition").val("");
		$.ajax({
			type : "post",
			url : "GetSelectedTC",
			data : $("#q_form").serializeArray(),
			dataType : "JSON",
			success : function(Result) {
				var tcuid =[];
				var size = Result.size;
				var ver = Result.ver;
				$.each(Result.sqlData, function(i, res) {
					if (uid == res.uID){
						$("#tr_uid").html(res.uID);
						$("#tr_tcName").html(res.tcName);
						$("#tr_tcKeyPoint").html(res.tcKeyPoint);
						$("#tr_tcTestData").html(res.tcTestData);
						$("#tr_tcProcess").html(res.tcProcess);
						$("#tr_tcResExp").html(res.tcResExp);
						$("#tr_NumKeyPoint").attr("value",res.numKeyPoint);
						$("#sub_numKeyPoint")[0].value = res.numKeyPoint;
					} 
				});
				var tmp = $("#"+uid+"_level01_succnum").text();
				$("#tr_Succ").attr("value",tmp);
				tmp = $("#"+uid+"_level01_retenum").text();
				$("#tr_retest").attr("value",tmp);
				tmp = $("#"+uid+"_level01_failnum").text();
				$("#tr_Fail").attr("value",tmp);
				tmp = $("#"+uid+"_level01_cantnum").text();
				$("#tr_Cant").attr("value",tmp);
				tmp = $("#"+uid+"_level01_waitnum").text();
				$("#tr_Wait").html(tmp);
				
				$("#tr_retest").attr("tcuid",uid);
				$("#tr_Succ").attr("tcuid",uid);
				$("#tr_Fail").attr("tcuid",uid);
				$("#tr_Cant").attr("tcuid",uid);
				
				/** 將測試結果種類寫入 Select中 **/
			 	var tok = $("#"+uid+"_level01_tr").attr("tok");
				$("#trStatus option").remove();
				
				for(o=0;o<trType.length;o++) {
					var selected = "";
					if (trType[o].sn == tok) {
						selected = " SELECTED";
					} 
					$("#trStatus").append("<option uid=\""+uid+"\" name=\""+trType[o].name+"\" val=\""+trType[o].value+"\" value=\""+(o+1)+"\" "+selected+">"+trType[o].name+ " ( " + trType[o].value + " ) </option>");
				}
				
				$("#dialog-fillTR").css("visibility", "visible");
				$("#dialog-fillTR").dialog({
					resizable : true,
					width : 700,
					height : 700,
					modal : true,
					buttons : {
						"關閉" : function() {
							/** 按下關閉即儲存 **/
							$("#sub_tr_retest")[0].value = $("#tr_retest").val();
							$("#sub_tr_Succ")[0].value = $("#tr_Succ").val();
							$("#sub_tr_Fail")[0].value = $("#tr_Fail").val();
							$("#sub_tr_Cant")[0].value = $("#tr_Cant").val();
							$("#sub_trSN")[0].value = $("#"+uid+"_level01_tr").attr("tok");
							$("#sub_edition")[0].value = $("#tr_edition").val();
							$("#sub_tcuid")[0].value = uid;
							
							$.ajax({
								type : "post",
								url : "SaveTR",
								data : $("#q_form").serializeArray(),
								dataType : "TEXT",
								success : function(Result) {
								}
							});
							
							$(this).dialog("close");
						}
					}
				});
				$("#dialog:ui-dialog").dialog("destroy");
			}, error : function(xhr, ajaxOptions, thrownError) {
				alert("出代誌啊!! \n\n"+xhr.status+"\n\n"+xhr.responseText);
			}
		});
	}
	
	
	/** 產生測試案例的資訊 **/
	function floyd() {
		/** 先清空舊有資料 **/
		$("#ConfirmSubTC").html("");
		$.ajax({
			type : "post",
			url : "GetSelectedTC",
			data : $("#q_form").serializeArray(),
			dataType : "JSON",
			success : function(Result) {
				var tcuid =[];
				var size = Result.size;
				var ver = Result.ver;
				$.each(Result.sqlData, function(i, res) {
					tcuid.push(res.uID);
					$("#ConfirmSubTC").append("<tr><th class=\"query\">測試識別代號：</th><td colspan=\"2\" class=\"query\"><input type=\"text\" value=\""
							+tcuid[i]+"\" disabled /></td><td rowspan=\"3\"></td></tr><tr><th class=\"query\">測試案例名稱：</th><td colspan=\"2\" class=\"query\"><input type=\"text\" value=\""
							+res.tcName+"\" disabled /></td></tr><tr><th class=\"query\">驗證重點數：</th><td colspan=\"2\" class=\"query\"><input type=\"text\" value=\""
							+res.numKeyPoint+"\" disabled /></td></tr><tr><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr><tr><th>驗證重點</th><th>測試資料</th><th colspan=\"2\">測試程序</th><th colspan=\"2\">預期結果</th></tr><tr><td id=\""+tcuid[i]+"_tcKeyPoint\">"
							+res.tcKeyPoint+"</td><td id=\""+tcuid[i]+"_tcTestData\">"
							+res.tcTestData+"</td><td id=\""+tcuid[i]+"_tcProcess\" colspan=\"2\">"
							+res.tcProcess+"</td><td id=\""+tcuid[i]+"_tcResExp\" colspan=\"2\">"
							+res.tcResExp+"</td><tr><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr><tr><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>");
				});
				
				$("#dialog-subTC").css("visibility", "visible");
				$("#dialog-subTC").dialog({
					resizable : true,
					width : 1000,
					height : 600,
					modal : true,
					buttons : {
						"確定" : function() {
							$("#sub_submitorComment").val("");
							$("#sub_submitorComment")[0].value = $("#tcSubmitComment").val();
							$("#sub_ver").val(ver);
							$.ajax({
								type : "post",
								url : "SubmitTC_v2",
								data : $("#q_form").serializeArray(),
								dataType : "TEXT",
								success : function(res) {
									if (res =="OK") {
										alert("完成提交");
									} else {
										alert("提交失敗");
									}
								}
							});
							
							$(this).dialog("close");
						},"關閉" : function() {
							$(this).dialog("close");
						}
					}
				});
				$("#dialog:ui-dialog").dialog("destroy");
			}, error : function(xhr, ajaxOptions, thrownError) {
				alert("出代誌啊!! \n\n"+xhr.status+"\n\n"+xhr.responseText);
			}
		});
	}

	function trStatusChange(obj) {
		var tok = $('select#trStatus option:selected').val();
		var value = $('select#trStatus option:selected').attr("val");
		var name = $('select#trStatus option:selected').attr("name");
		var uid = $('select#trStatus option:selected').attr("uid");
		var mm = name+ " (" + value + ")";
		
		$("#"+uid+"_level01_tr").attr("tok",tok);
		
		$("#"+uid+"_level01_tr").html(mm);
	}
	
	/**
		判斷CheckBox勾選的數目以決定是否要勾選 CheckALL 
		a 是 Class的名稱
	**/
	function chk(a) {
		var itemNum = $("."+a).size();
		var chkNum = 0;
		var isChecked = false;
		$("."+a).each(function() {
			isChecked = $(this).prop("checked");
			if (isChecked){
				chkNum++
			}
		});
		if (itemNum == chkNum) {
			$("#"+a+"CheckALL").prop("checked",true);			
		} else {
			$("#"+a+"CheckALL").prop("checked",false);
		}
	}
	
	/** 匯入MR月需求 **/
	function Click_importMR(){
		$.ajax({	//至遠端讀取存放XML的目錄，列出所有的月份
			type : "post",
			url : "CheckMRXml",
			dataType : "JSON",
			success : function(queryResult) {
				if (queryResult != null) {
					/** 先清空選擇清單後，再建立 **/
					$("tbody[id=mrLevel_00_body] tr").remove();
					
					var optStart = "<option fileName=\"";
					var optEnd = "</option>";
					if (queryResult.length >0 ) {
						$.each(queryResult, function(i, res) {
							var bgcolor=getbgColor((i+1))
							var fileID = res.year+res.month;	//fileID 代表是從那年那個月份的XML取得的資料
							var numList = CXML.length; 
							var isNotExist = true; 
							$.each(CXML, function(a, result) {
								if (result.id == fileID ) {
									isNotExist = false;
								}
							});
							
							if (isNotExist) {
								/** list物件中，建立所有月份的勾選陣列 **/
								CXML.push({id:fileID,cont:[]});
							}
							
							$("#mrLevel_00_body").append("<tr bgcolor="+bgcolor+"><td><img id=\""+fileID+"_img\" src='pics/cross.PNG'/></td><td>"+(i+1)+"</td><td>" + res.year + res.month + "&nbsp;MR</td><td><button type=\"button\" id=\"but_"+fileID+"\" onClick=\"showbody('"+fileID+"')\">選擇</button></td></tr>");
							$("#mrSel").append(optStart + res.fileName +"\" id=\"opt_"+ fileID +"\">MR " + res.year + "年" + res.month + "月"+ optEnd + "<br/>");
						});						
					}
				} else {
					alert("後端存取有出現問題！");
				}
			},error : function(xhr, ajaxOptions, thrownError) {
				alert("出代誌啊!! \n\n"+xhr.status+"\n\n"+xhr.responseText);
			}
		});
		
		$("#dialog-mrLevel_00").css("visibility", "visible");
		$("#dialog-mrLevel_00").dialog( {
			resizable : true,
			width : 335,
			height : 400,
			modal : true,
			buttons : {
				"匯入" : function() {
					/**
					1. 單身中是否已存在此項，以mrid為準，若無則加入單身中
					2. 若比對中發現有重覆的，則該項不予匯入，但在最後要跳出視窗讓顯示未匯入的「id」「mrdescription」
					**/
					
					var ind = $("#mainTbody tr").length+1;
					var mbItem = $("#mainTbody tr");
					var isConflictExist = false;	//記錄這次匯入是否發生過衝突，以決定是否結束後要用Alert Message
					var conflictMess ="";
					
					$.each(CXML, function(i, res) {	//每個月份都要檢查
						/**
						1. 如果該月份的陣列大於0，表示有打開過
						2. res.cont 是該月份的測試項目陣列
						**/
						if (res.cont.length>0) {
							/**
							1. 進入該月份，逐一比對 測試項目
							**/
							var tpName = $("#hidden_testPlanName")[0].value;
							$.each(res.cont,function(m,content) {
								if (content.isSelected) {
									var isConflicted = false;	//決定這筆測試項目是否算衝突
									
									$.each(mbItem,function(n,mbi) {
										if (mbi.id == content.mrid && content) {
											isConflicted = true;
										}
									});
									
									if (isConflicted) {
										isConflictExist = true;
										conflictMess += content.yymm + "：" + content.mrdescription + "\n";
										return true; //如同for 迴圈的continue												
									} else {
										var itemLength = $("#mainTbody tr").length;
										var bgcolor=getbgColor((itemLength+1));
										var sourceid = CXML[i].cont[m].sourceid;
										var mrdescription = CXML[i].cont[m].mrdescription;
										var mrid = content.mrid;
										sourceid = (sourceid==undefined)?"":sourceid;
										
										var tester = "";
										if (CXML[i].cont[m].tester != undefined) {
											$.each(CXML[i].cont[m].tester,function(indexTester,user) {
												tester += "<li class=\"mrTestOwner\" nickName=\""+user.nickName+"\" val=\""+user.userID+"\">"+user.nickName+"</li>";
											});	
										}
										
										$("#mainTbody").append("<tr id=\""+mrid+"\" sel=\""+i+"\" cont=\""+m+"\" isInDB=\"false\" class=\"inTmp\" ondblclick=\"trDoubleClick('"+i+"','"+m+"','"+mrid+"')\" bgcolor="+bgcolor+"><td>"+ind+"</td><td><input type=\"text\" size=\"21\" sel=\""+i+"\" cont=\""+m+"\"  onkeyup=\"saveBack01('"+i+"','"+m+"','"+mrid+"')\" value=\""+sourceid+"\" attr=\"sourceid\" mrid=\""+mrid+"\"  /></td><td><textarea id='"+mrid+"_mrDesc' sel=\""+i+"\" cont=\""+m+"\" attr=\"mrdescription\" onkeyup=\"saveBack01('"+i+"','"+m+"','"+mrid+"')\" mrid=\""+mrid+"\"  >"+mrdescription+"</textarea></td><td><ul id=\""+mrid+"_mrTester\" >"+tester+"</ul></td><td>"+df(1)+"</td><td id=\"lupt_"+mrid+"\">"+df(1)+"</td><td width=\"235\"><button id='"+mrid+"_selTC' mrid=\""+mrid+"\" class='selTC' onClick=\"Click_selTC(this)\" type=\"button\" DISABLED>選擇案例</button><button id='"+mrid+"_fillTR' mrid=\""+mrid+"\" class='fillTR' onClick=\"Click_fillTR(this)\" type=\"button\" DISABLED>登打結果</button><button id='"+mrid+"_refItem' mrid=\""+mrid+"\" class='refItem fromImport' yymm=\""+content.yymm+"\" sel=\""+i+"\" cont=\""+m+"\" onClick=\"Click_refItem(this)\" type=\"button\" DISABLED>重新匯入</button><br/><button id='"+mrid+"_subTC' mrid=\""+mrid+"\" class='subTC' onClick=\"Click_subTC(this)\" type=\"button\" DISABLED>送審案例</button><button id='"+mrid+"_subTR' mrid=\""+mrid+"\" class='subTR' onClick=\"Click_subTR(this)\" type=\"button\" DISABLED>送審結果</button><button id='"+mrid+"_infoItem' mrid=\""+mrid+"\" tpname=\""+tpName+"\" class='infoItem' onClick=\"Click_infoItem(this)\" type=\"button\" DISABLED>相關資訊</button></td></tr>");
										ind++;	
									}
								}
							});
						}
					});
					
					$("#saveTPBody").removeAttr("disabled");
					$(this).dialog("close");
				},
				"關閉" : function() {
					/**
					檢查有沒有被選擇，沒有就直接關閉
					**/
					$(this).dialog("close");
				}
			}
		});
	}

	/** 建立項目按鈕 **/	
	function createMRItem() {
		var ind = $("#mainTbody tr").length+1;
		var bgcolor=getbgColor(ind);
		var mrid = new Date().getTime();
		var obj = {isSelected:true,isFromImport:false,isFromImport:false,fromXML:999999,mrid:mrid,module:'',mrdescription:'',sourceid:'',mrno:'',createdate:'',onlinedate:'',process:'',yymm:'',desc:'',programmer:[],propose:[],designer:[],designpm:[]};
		CXML[0].cont.push(obj);
		var m = CXML[0].cont.length-1;
		var i =0;
		var tpName = $("#hidden_testPlanName")[0].value;
		$("#mainTbody").append("<tr id=\""+mrid+"\" sel=\""+i+"\" cont=\""+m+"\" isInDB=\"false\" class=\"inTmp\" ondblclick=\"trDoubleClick('"+i+"','"+m+"','"+mrid+"')\" bgcolor="+bgcolor+"><td>"+ind+"</td><td><input type=\"text\"  size=\"21\" value=\"\" sel=\""+i+"\" cont=\""+m+"\"  onkeyup=\"saveBack01('"+i+"','"+m+"','"+mrid+"')\" attr=\"sourceid\" mrid=\""+mrid+"\"  /></td><td><textarea id='"+mrid+"_mrDesc' sel=\""+i+"\" cont=\""+m+"\" attr=\"mrdescription\" mrid=\""+mrid+"\" onkeyup=\"saveBack01('"+i+"','"+m+"','"+mrid+"')\" ></textarea></td><td><ul id=\""+mrid+"_mrTester\"></ul></td><td>"+df(1)+"</td><td id=\"lupt_"+mrid+"\">"+df(1)+"</td><td width=\"235\"><button id='"+mrid+"_selTC' mrid=\""+mrid+"\" class='selTC' onClick=\"Click_selTC(this)\" type=\"button\" DISABLED>選擇案例</button><button id='"+mrid+"_fillTR' mrid=\""+mrid+"\" class='fillTR' onClick=\"Click_fillTR(this)\" type=\"button\" DISABLED>登打結果</button><button id='"+mrid+"_refItem' mrid=\""+mrid+"\" class='refItem fromHomeMade' sel=\""+i+"\" cont=\""+m+"\" onClick=\"Click_refItem(this)\" type=\"button\" DISABLED>重新匯入</button><br/><button id='"+mrid+"_subTC' mrid=\""+mrid+"\" class='subTC' onClick=\"Click_subTC(this)\" type=\"button\" DISABLED>送審案例</button><button id='"+mrid+"_subTR' mrid=\""+mrid+"\" class='subTR' onClick=\"Click_subTR(this)\" type=\"button\" DISABLED>送審結果</button><button id='"+mrid+"_infoItem' mrid=\""+mrid+"\" tpname=\""+tpName+"\" class='infoItem' onClick=\"Click_infoItem(this)\" type=\"button\" DISABLED>相關資訊</button></td></tr>");
		$("#saveTPBody").removeAttr("disabled");
	}
	
	function Click_assignTestor() {
		pickTPOwner("mrTester");
	}
	
	function Click_deleteMRitem(obj) {
		$("#dialog-delMR").prop("title","刪除測試項目");
		var mrid = $(obj).attr("mrid");
		$("#sub_mrid").val(mrid);
		var mrdescription = $("#"+mrid+"_mrDesc").val();
		$("#delMR_mrdesciption").html(mrdescription);
		
		$("#dialog-delMR").dialog({
			resizable : true,
			width : 600,
			height : 300,
			modal : true,
			buttons : {
				"確定" : function() {
					$.ajax({										//取得此測試項目原本所設定的測試案例
						type : "post",
						url : "DelMRitem",
						data : $("#q_form").serializeArray(),
						dataType : "text",
						success : function(queryResult) {
							$("#"+mrid).remove();
							refreshUI("mainTbody",1);
						}, error : function(xhr, ajaxOptions, thrownError) {
							alert("出代誌啊!! \n\n"+xhr.status+"\n\n"+xhr.responseText);
						}
					});
					$(this).dialog("close");
				},"關閉" : function() {
					$(this).dialog("close");
				}
			}
		});
	}
	
	
	/** 移除已選擇的測試案例 **/
	function Click_removeSelTC(uid) {
		$("#tr_"+uid).remove();
		$("#selectedTCBody tr").each(function(m){
			var bgcolor=getbgColor((m+1));
			$(this).attr("bgcolor",bgcolor);
		});
		
		$("#selectedTCBody td:first-child").each(function(a){
			$(this).html((a+1));
		});
	}
	
	/** 點選欲送審的測試案例 **/
	function Click_queryTC() {
		var isNotBlank = false;
		$(".require_from_group").each(function() {
			if (!($.trim( $(this).val() ) == "")) {
				isNotBlank = true;
			}
		});
		$("#queryTCBody tr").remove();
		
		if (isNotBlank) {
			$("#q_message").html("請至少輸入一個查詢欄位");
		} else { //表示有輸入，要開始查詢
			$("#q_message").html("");	//效果不太一樣，頂著先
			
			$.ajax({
				type : "post",
				url : "QueryTC",
				data : {q_tcID:$("#q_tcID").val(),q_tcName:$("#q_tcName").val()},
				dataType : "JSON",
				success : function(queryResult) {
					if (queryResult.strSQL[0]["result"] == "No Result") {
						$("#q_message").html("沒找到!!");
					} else {
					//	$("#q_message").html(queryResult.strSQL[0]["strSQL"]);  //為了看執行SQL語句用
								
						$.each(	queryResult.sqlData,function(i,res) {
							var bgcolor=getbgColor((i+1));
							var tcName = res.tcName;
							var uID = res.uID;
							var tcID = res.tcID;
							$("#ReaultNum").html("共有"+(i+1)+"筆資料");
							$("#queryTCBody").append("<tr bgcolor=\""+bgcolor+"\"><td>"
									+ (i+1)
									+ "</td><td>"
									+ tcID
									+ "</td><td>"
									+ tcName
									+ "</td><td>"
									+ "<button onClick=\"Click_selectTC('"+res.uID+"')\" id='"+uID+"' tcid='"+res.tcID+"' tcName='"+tcName+"' type=\"button\">選擇</button></td></tr>");
						});
						$("#queryTCDiv").css("visibility","visible");
					}
				}
			});
		}
	}
	
	/** 選擇所要的測試案例至選擇清單中 **/
	function Click_selectTC(uid) {
		
		var isNotExist = true;
		$("#selectedTCBody tr").each(function(i) {
			var id = $(this).attr("id");		//this 就是這次 each 的主角selectedTCBody tr 中的 tr，function 中的i是index
			var tcName = $(this).attr("tcName");
			if (id == ("tr_"+uid)) {
				isNotExist = false;
				alert("第"+(i+1)+"筆案例("+tcName+")已在清單中！");
			}
		});
		
		if (isNotExist) {
			var tcid = $("#"+uid).attr("tcid");
			var tcName = $("#"+uid).attr("tcName");
			var i = ($("#selectedTCBody tr").length+1);
			var bgcolor=getbgColor(i);
			$("#selectedTCBody").append("<tr id=\"tr_"+uid+"\" uid=\""+uid+"\" tcid=\""+tcid+"\" bgcolor=\""+bgcolor+"\"><td>"+(i++)+"</td><td>"+tcid+"</td><td>"+tcName+"</td><td><button onClick=\"Click_removeSelTC('"+uid+"')\" type='button'>移除</button></td></tr>");	
		}
	}
	
	/** 將所選擇的測試案例，正式與測試項目建立連結 **/
	function Click_saveTC() {
		var i = $("#selectedTCBody tr").length;
		var mrid = $("#saveTCselected").attr("mrid");
		
		$("#confirmMessage").html("確定儲存？");
		$("#dialog-saveMRItemTCmapping").dialog({
			resizable : true,
			width : 200,
			height : 200,
			modal : true,
			buttons : {
				"儲存" : function() {
					if (i>0){
						$("#"+mrid+"_subTC").removeAttr("disabled");	//可以送審案例了
						$("#"+mrid+"_fillTR").removeAttr("disabled");	//可以登打結果了
					} else {
						$("#"+mrid+"_subTC").attr("disabled","disabled");	//不行送審案例
						$("#"+mrid+"_fillTR").attr("disabled","disabled");	//不行登打結果
					}
					$("#"+mrid+"_subTR").attr("disabled","disabled");	//不行提交結果
					
					var selectTCList =[];
					$("#selectedTCBody tr").each(function(i) {
						var uID = $(this).attr("uid");
						selectTCList.push(uID);
					});
					
					$("#sub_selectTCList")[0].value = JSON.stringify(selectTCList);
					
					$.ajax({										//取得此測試項目原本所設定的測試案例
						type : "post",
						url : "SetMRTCmapping",
						data : $("#q_form").serializeArray(),
						dataType : "text",
						success : function(queryResult) {
							
						}, error : function(xhr, ajaxOptions, thrownError) {
							alert("出代誌啊!! \n\n"+xhr.status+"\n\n"+xhr.responseText);
						}
					});
					
					$(this).dialog("close");
				},
				"關閉" : function() {
					$(this).dialog("close");
				},
			}
		});	
	}
	
	/** 選擇案例 **/
	function Click_selTC(obj) {
		var mrid = $(obj).attr("mrid");
		$("#saveTCselected").attr("mrid",mrid);
		
		$("#selectedTCBody tr").remove();				//清除原本視窗中的"已選擇案例"
		$("#queryTCBody tr").remove();					//清除原本視窗中的"查詢結果"
		$("#queryTCDiv").css("visibility","hidden");	//當使用都，先前點過一次"送出查詢"，再點其它測試項目的選擇案例時，會發現"查詢結果"會還在，故在此要隱藏
		$("#sub_mrid").val(mrid);
		
		$.ajax({										//取得此測試項目原本所設定的測試案例
			type : "post",
			url : "GetMRTCmapping",
			data : $("#q_form").serializeArray(),
			dataType : "JSON",
			success : function(queryResult) {
				if (queryResult.size > 0) {
					$.each(queryResult.sqlData, function(i, res) {
						var uid = res.uID;
						var tcid = res.tcID;
						var m = ($("#selectedTCBody tr").length+1); 
						var bgcolor=getbgColor(m);
						$("#selectedTCBody").append("<tr id=\"tr_"+uid+"\" uid=\""+uid+"\" mrid=\""+mrid+"\" tcid=\""+tcid+"\" bgcolor=\""+bgcolor+"\"><td>"+(i+1)+"</td><td>"+tcid+"</td><td>"+res.tcName+"</td><td><button onClick=\"Click_removeSelTC('"+uid+"')\" type='button'>移除</button></td></tr>");	
					});
				}
			}, error : function(xhr, ajaxOptions, thrownError) {
				alert("出代誌啊!! \n\n"+xhr.status+"\n\n"+xhr.responseText);
			}
		}); 
		
		$("#dialog-selTC").css("visibility", "visible");
		$("#dialog-selTC").dialog({
			resizable : true,
			width : 750,
			height : 500,
			modal : true,
			buttons : {
				"關閉" : function() {
					$(this).dialog("close");
				}
			}
		});
	}
	
	/**  **/
	function Click_subTC(obj) {
		var mrid = $(obj).attr("mrid");
		$("#sub_mrid").val(mrid);
		floyd();
	}
	/** 登打結果 **/
	function Click_fillTR(obj) {
		var mrid = $(obj).attr("mrid");
		var mrdescription = $("#"+mrid+"_mrDesc").val();
		var ver = $(obj).attr("ver");
		$("#TRlecel_01_mrDesc").html(mrdescription);
		$("#sub_mrid").val(mrid);
		napoleon("fill");
		$("#dialog-TRlevel_01").prop("title","登打測試結果");
		$("#dialog-TRlevel_01").dialog({
			resizable : true,
			width : 1100,
			height : 600,
			modal : true,
			buttons : {
				"關閉" : function() {
					/** 檢查目前這個測試項目，能否提審測試結果**/
					checkIsSubmitTRable(mrid,ver);
					$(this).dialog("close");
				}
			}
		});
		$("#dialog:ui-dialog").dialog("destroy");
		
		$(".fillInTR").each(function() {
			$(this).removeAttr("disabled");
		});
	}
	
	/** 送審結果 **/
	function Click_subTR(obj) {
		var mrid = $(obj).attr("mrid");
		var mrdescription = $("#"+mrid+"_mrDesc").val(); 
		$("#TRlecel_01_mrDesc").html(mrdescription);
		$("#sub_mrid").val(mrid);
		napoleon("sub");
		
		$(".fillCol").each(function() {
			$(this).remove();
		});
		
		$(".fillInTR").each(function() {
			$(this).attr("disabled","disabled");
		});
		
		$("#dialog-TRlevel_01").prop("title","送審測試結果");
		$("#subTR_mrdesciption").html(mrdescription);
		
		$("#dialog-TRlevel_01").dialog({
			resizable : true,
			width : 1100,
			height : 600,
			modal : true,
			buttons : {
				"送審" : function() {
					$("#dialog-subTR").css("visibility", "visible");
					$("#dialog-subTR").dialog({
						resizable : true,
						width : 320,
						height : 400,
						modal : true,
						buttons : {
							"確定" : function() {
								$("#sub_tpidFileUpload").val( $("#sub_tpid").val() );
								$("#sub_mridFileUpload").val( $("#sub_mrid") );
								$("#loginUserFileUpload").val( $("#loginUser").val() );
								$("#form_TRFileUpload").submit();								
								$("#sub_submitorComment").val("");
								$("#sub_submitorComment").val( $("#trSubmitComment").val() );
								$.ajax({
									type : "post",
									url : "SubmitTR_v2",
									data : $("#q_form").serializeArray(),
									dataType : "TEXT",
									success : function(res) {
										if (res =="OK") {
											alert("完成提交");
										} else {
											alert("提交失敗");
										}
									}, error : function(xhr, ajaxOptions, thrownError) {
										alert("出代誌啊!! \n\n"+xhr.status+"\n\n"+xhr.responseText);
									}
								});
								$(this).dialog("close");
							},"關閉" : function() {
								$(this).dialog("close");
							}
						}
					});
					
					$(this).dialog("close");
				},"關閉" : function() {
					$(this).dialog("close");
				}
			}
		});
	}
	/** 重新匯入 **/
	function Click_refItem(obj) {
		/**
			1. Confirmation
			2. get yymm Column
			3. Require matrix has to be reserved
			4. save directly
			5. 
		**/
		var indCont = $(obj).attr("cont");
		var mrid = $(obj).attr("mrid");
		
		$("#sub_yymm").val( $(obj).attr("yymm") );
		$("#sub_mrid").val( $(obj).attr("mrid") );
		$.ajax({
			type : "post",
			url : "RefMRItem",
			data : $("#q_form").serializeArray(),
			dataType : "JSON",
			success : function(queryResult) {
				$.each(queryResult, function(i, res) {
					//WriteBackToCDB
					CDB[indCont].mrdescription = res.mrdescription;
					CDB[indCont].sourceid = res.sourceid;
					CDB[indCont].createdate = res.createdate;
					CDB[indCont].onlinedate = res.onlinedate;
					CDB[indCont].desc = res.desc;
					CDB[indCont].module = res.module;
					CDB[indCont].process = res.process;
					CDB[indCont].propose = res.propose;
					CDB[indCont].designer = res.designer;
					CDB[indCont].designpm = res.designpm;
					CDB[indCont].reference = res.reference;
					CDB[indCont].programmer = res.programmer;
					CDB[indCont].tester = res.tester;
					//現在要改變UI
					$("#"+mrid+ " td:nth-child(2) input").val(res.sourceid);
					$("#"+mrid+ " td:nth-child(3) textarea").val(res.mrdescription);
					var tpoStrForUI ="<ul>";
					$.each(res.tester,function(i,rest) {
						tpoStrForUI += "<li class=\"mrTestOwner\" nickName=\""+rest.nickName+"\" val=\""+rest.userID+"\">"+rest.nickName+"</li>";						
					});
					tpoStrForUI += "</ul>";
					$("#"+mrid+ " td:nth-child(4)").html(tpoStrForUI);
					$("#"+mrid+ " td:nth-child(6)").html(df(1));
					$("#"+mrid+ "_fillTR").attr("disabled","disabled");
					$("#"+mrid+ "_subTR").attr("disabled","disabled");
					$("#"+mrid+ "_subTC").attr("disabled","disabled");
					alert("重新匯入成功");
				});
			}, error : function(xhr, ajaxOptions, thrownError) {
				alert("出代誌啊!! \n\n"+xhr.status+"\n\n"+xhr.responseText);
			}
		});
	}
	
	/** 新增一筆測試項目的需求矩陣 tr **/
	function Click_addReqMapping(obj) {
		var mrid = $(obj).attr("mrid");
		var numRequireLog = $("#requireLog tr").size();
		var ind = (numRequireLog +1) ;
		var bgcolor=getbgColor(ind);
		$("#requireLog").append("<tr bgcolor="+bgcolor+" id=\""+ind+"_req\" ><td><button onClick=\"Click_removeReqMapping(this)\" ind=\""+ind+"\" type=\"button\">－</button></td><td id=\""+ind+"_ind\">"+ind+"</td><td><input id=\""+mrid+"_requireID_"+ind+"\" size=\"10\" type=\"text\"/></td><td><input id=\""+mrid+"_swdsID_"+ind+"\" size=\"10\" type=\"text\"/></td><td><input id=\""+mrid+"_sitrID_"+ind+"\" size=\"10\" type=\"text\"/></td></tr>");
	}
	
	function filter(str){
		var res = "";
		if (str!="undefined") {
			res = str;
		}
		return res;
	}
	
	function Click_removeReqMapping(obj) {
		var ind = $(obj).attr("ind");
		$("#"+ind+"_req").remove();
		refreshUI("requireLog",2);
	}
	
	/** 對測試計畫案的測試項目進行儲存 **/
	function Click_saveMRItem() {
		/* 
			檢查目前Content內容
			1. onlinedate
			2. mrdescription
			3. yymm
			4. createdate
		*/
		var isCompleted = true;
		var gg = "";
		for(i=0 ;i<CXML.length;i++) {
			for(j=0 ;j<CXML[i].cont.length;j++) {
				if (CXML[i].cont[j].isSelected) {
					str = CXML[i].cont[j].mrdescription;
					if (str == undefined || $.trim(str) =="") {
						isCompleted = false;
						str += " ";
						gg += str;
					}
					str = CXML[i].cont[j].yymm;
					if (str == undefined || $.trim(str) =="") {
						isCompleted = false;
						str += " ";
						gg += str;
					}
					str = CXML[i].cont[j].onlinedate;
					if (str == undefined || $.trim(str) =="") {
						isCompleted = false;
						str += " ";
						gg += str;
					}
					str = CXML[i].cont[j].createdate;
					if (str == undefined || $.trim(str) =="") {
						isCompleted = false;
						str += " ";
						gg += str;
					}
				}
			}
		}
		for(i=0 ;i<CDB.length;i++) {
			str = CDB[i].mrdescription;
			if (str == undefined || $.trim(str) =="") {
				isCompleted = false;
				str += " ";
				gg += str;
			}
			str = CDB[i].yymm;
			if (str == undefined || $.trim(str) =="") {
				isCompleted = false;
				str += " ";
				gg += str;
			}
			str = CDB[i].onlinedate;
			if (str == undefined || $.trim(str) =="") {
				isCompleted = false;
				str += " ";
				gg += str;
			}
			str = CDB[i].createdate;
			if (str == undefined || $.trim(str) =="") {
				isCompleted = false;
				str += " ";
				gg += str;
			}
		}
		
		/** 檢查UI元件上的必要欄位是否有輸入 **/
		if (isCompleted) {
			$(".inTmp").each(function(i){
				isInDB = $(this).attr("isInDB");	 //確認儲存點是在CDB or CXML
				
				if (isInDB == "false") {
					var indSel = $(this).attr("sel");
					var indCont = $(this).attr("cont");
					CDB.push(CXML[indSel].cont[indCont]);	//將UI中, inDB為false且isSelected為true的記錄，複製至CDB
					
					/** 將UI標示改為在DB中 **/
					$(this).removeClass("inTmp");
					$(this).addClass("inDB");
					$(this).attr("inInDB","true");	
				} else {
				}
			});
			
			$("#sub_CDB").val(JSON.stringify(CDB));
			
			$.ajax({
				type : "post",
				url : "SaveMRItems",
				data : $("#q_form").serializeArray(),
				dataType : "text",
				success : function(queryResult) {
					//showProcess();
					if (queryResult=="OK") {
						$(".selTC").removeAttr("disabled");
						$(".infoItem").removeAttr("disabled");
						$(".refItem.fromImport").removeAttr("disabled");
						alert("儲存完成!");						
					}
				}, error : function(xhr, ajaxOptions, thrownError) {
					alert("出代誌啊!! \n\n"+xhr.status+"\n\n"+xhr.responseText);
				}
			}); 
		} else {
			alert("儲存失敗\n\n 因欄位輸入不完整!\n\n"+gg);
		}
	}
	
	function pickTPOwner(er) {
		/**
		紀錄目前有指派給此ID的角色
		而先記下來，等等的CheckBox要預先將它打勾
		陣列：	tmpSelectedRole	用來儲存目前的勾選
		i：		流程引擎中的groupId
		v：		流程引擎中的description
		**/
		var tmpSelectedRole = [];
		var mrid = $("#sub_mrid").val();

		if (er == "tpOwner") {
			$("#sub_er").val("1");
			$(".selectdTPOwner").each(function(items) {
				var i = $(this).attr("id");
				var v = $(this).attr("val");
				var item = {"id":i,"val":v}
				tmpSelectedRole.push(item);
			});
		}
		if (er == "mrTester") {
			$("#sub_er").val("1");
			var testerSet = $("#"+mrid+ " td:nth-child(4) li");
			if (testerSet != undefined) {
				$.each(testerSet,function(i){
					var userid = $(this).attr("val");
					var nickName = $(this).attr("nickName");
					var item = {"id":userid,"val":nickName}
					tmpSelectedRole.push(item);
				});	
			}
		}
		/**
			去後端取得所有角色的名單
		**/
		$.ajax({
			type : "post",
			url : "GetTPOwner",
			data : $("#q_form").serializeArray(),
			dataType : "JSON",
			success : function(queryResult) {
				$("tbody[id=tBodyTPOwner] tr").remove();		//所有計畫負責人名單的 Table
				$.each(queryResult, function(i, res) {
					var bgcolor=getbgColor((i+1));
					var userID = res.userID;
					var nickName = res.nickName;				
					var ckd = "";								//用來決定是否要勾選
					
					/** 比對陣列中的元素，一樣的groupId就要勾起來 **/
					if (tmpSelectedRole.length >0) {
						for(m=0;m<tmpSelectedRole.length;m++){
							if (er == "tpOwner") {
								if (tmpSelectedRole[m].id == userID) {
									ckd = "checked=\"checked\"";
								}	
							} else {
								if (tmpSelectedRole[m].val == nickName) {
									ckd = "checked=\"checked\"";
								}
							}
						}	
					}
					
					$("#tBodyTPOwner").append("<tr bgcolor="+bgcolor+"><td><input type=\"checkbox\" class=\"tpo\" value=\""+userID+"\" nickName=\""+nickName+"\"" + ckd +"/></td><td>"+(i+1)+"</td><td>"+nickName+"</td></tr>");
				});
		
				$("#dialog-Group").dialog({
					resizable : true,
					width : 260,
					height : 500,
					modal : true,
					buttons : {
						"關閉" : function() {
							/** 先清空顯示螢幕上已有的選項，以免愈append愈多 **/
							$("#"+er+" li").remove();
							$("#sub_"+er+"List").val("");	//先將要送出去的清空
							var tpoStr = "";
							if (er=="tpOwner") {
								/** 測試案負責人 **/
								$(".tpo").each(function() {
									if ($(this).is(":checked")) {
										var tpOwnerID = $(this).val();
										var tpn = $(this).attr("nickname");	//人員的暱稱(顯示給看的名稱)
										$("#"+er).append("<li class=\"selectdTPOwner\" val=\""+tpn+"\" id=\""+tpOwnerID+"\">"+tpn+"</li>");
										tpoStr += tpOwnerID +",";
									}
								});	
							} else {
								/** 測試項目負責人 **/
								var tmp = 0
								var tpoStrForUI ="<ul>";
								$(".tpo").each(function(t) {
									if ($(this).is(":checked")) {
										var userID = $(this).val();
										var nickName = $(this).attr("nickName");
										tpoStrForUI += "<li class=\"mrTestOwner\" nickName=\""+nickName+"\" val=\""+userID+"\">"+nickName+"</li>";
										tpoStr += userID +",";
									}
								});
								tpoStrForUI += "</ul>";
								
								$("#info_assignedTester").html(tpoStrForUI);
								$("#"+mrid+ " td:nth-child(4)").html(tpoStrForUI);
							}
							
							/** 將選取的人員，加到q_form的欄位 **/
							if (tpoStr.length != 0){
								$("#sub_"+er+"List").val(tpoStr);
							}
							
							/** 寫入DB **/
							$.ajax({
								type : "post",
								url : "SaveOwner",
								data : $("#q_form").serializeArray(),
								dataType : "text",
								success : function(queryResult) {
								}, error : function(xhr, ajaxOptions, thrownError) {
									alert("出代誌啊!! \n\n"+xhr.status+"\n\n"+xhr.responseText);
								}
							});
							$(this).dialog("close");
						}
					}
				});
				$("#dialog-Group").css("visibility", "visible");
				
			}, error : function(xhr, ajaxOptions, thrownError) {
				alert("出代誌啊!! \n\n"+xhr.status+"\n\n"+xhr.responseText);
			}
		});
	}
	
	/** 取得指定MR月份的 測試項目  **/
	function getMRBody(fileID,isChecked,isNeedAppend){	//(指定月份,是否全選,是否產生單身)
		$("#fileName").val("icssor%20"+fileID+".xml");	
		
		$.ajax({
			type : "post",
			url : "GetMRBody",
			data : $("#q_form").serializeArray(),
			dataType : "JSON",
			success : function(queryResult) {
				$("tbody[id=mrLevel_01_body] tr").remove();		//先清空查詢結果，避免關閉Dialog後，再打開Dialog時，先前的東西還在
				var numQuery = queryResult.length;
				$.each(queryResult, function(i, res) {
					var bgcolor=getbgColor((i+1));
					
					/**逐一檢查陣列，將該月份的MR測試項目內容，放進cont陣列中**/
					for (a=0;a<CXML.length;a++) {
						var numCont = CXML[a].cont.length;
						if (CXML[a].id == fileID && numCont!=numQuery){
							res["isSelected"]=isChecked;	//原本JSON回傳回來的格式，新增一屬性，以記錄是否被勾選
							res["isFromImport"]=true;			//重新匯入要使用的欄位
							res["fromXML"]=fileID;			//來自那個XML檔
							CXML[a].cont.push(res);		
						}	
					}
					
					/** 若是開視窗的情況下，就需要把Table的單身做出來 **/
					if (isNeedAppend){
						/** 將該月份的所有測試項目，加入Table，讓人可選擇 **/
						$("#mrLevel_01_body").append("<tr bgcolor="+bgcolor+"><td><input type=\"checkbox\" onClick=\"chk('isImport')\" class=\"isImport\" yymm=\""+fileID+"\" sourceid=\""+res.sourceid+"\" mrid=\""+res.mrid+"\" mrdescription=\""+res.mrdescription+"\" /></td><td>"+(i+1)+"</td><td>" +res.mrdescription+"</td></tr>");	
					}					
				});
			}
		});
	}
	
	/** 列出指定月份的mr需求供點選 **/
	function showbody(fileID) {
		getMRBody(fileID,false,true);
		$("#isImportCheckALL").prop("checked",false);
		
		$("#opt_"+fileID).attr("selected","true");
		$("#dialog-mrLevel_01").css("visibility", "visible");
		
		/** 指定月份內，可供勾選測試項目 **/
		$("#dialog-mrLevel_01").dialog( {
			resizable : true,
			width : 800,
			height : 400,
			modal : true,
			buttons : {
				"關閉" : function() {
					/**
					檢查有沒有被選擇，沒有就直接關閉
					**/
					var isChecked = false;
					$(".isImport").each(function() {
						if ($(this).is(":checked")) {
							for(i=0 ;i<CXML.length;i++) {
								if (CXML[i].id ==fileID) {
									for(j=0 ;j<CXML[i].cont.length;j++) {
										var mrid = $(this).attr("mrid");
										if (CXML[i].cont[j].mrid ==mrid ) {
											CXML[i].cont[j].isSelected = true;
										}
									}
								}	
							}
							isChecked = true;
						}
					});
					if (isChecked) {
						$("#"+fileID+"_img").attr("src","pics/check.PNG");
					}
					$(this).dialog("close");
				}
			}
		});
	}
	
	/** 供雙擊測試項目時，取得多值屬性(ex:tester, designer..)的函數 **/
	function setAttr(attr,indSel,indCont,isInDB) {
		if (isInDB == "true") {
			$("#detail_"+attr).val( CDB[indCont][attr] );
		} else {
			$("#detail_"+attr).val( CXML[indSel].cont[indCont][attr] );
			$("#detail_"+attr).attr("sel",indSel);
			$("#detail_"+attr).attr("cont",indCont);	
		}
	}
	
	/** 將XML的的designer,tester等內容，判斷內容包含了幾個人以輸出 **/
	function erList(er,tar) {
		$("#detail_"+tar).html("");
		
		if (er != undefined) {
			if (tar =="reference") {
				var size = er.length; 
				for(i=0;i<size;i++) {
					$("#detail_reference").append("<li class=\"selectdreference\" nickName=\""+er[i]+"\">"+er[i]+"</li>");	
				}
			} else {
				var size = er.length; 
				for(i=0;i<size;i++) {
					$("#detail_"+tar).append("<li class=\"selectd"+tar+"\" nickName=\""+er[i].nickName+"\" userID=\""+er[i].userID+"\">"+er[i].nickName+"</li>");	
				}	
			}
		}
	}
	function saveBack01(indSel,indCont,mrid) {
		isInDB = $("#"+mrid).attr("isInDB");	 //確認儲存點是在CDB or CXML
		var sourceid = $("#"+mrid+" td:nth-child(2) input").val();
		var mrdescription = $("#"+mrid+" td:nth-child(3) textarea").val();
		if (isInDB == "true") {
			CDB[indCont].sourceid = sourceid;
			CDB[indCont].mrdescription=mrdescription;
		} else {
			CXML[indSel].cont[indCont].sourceid =sourceid;
			CXML[indSel].cont[indCont].mrdescription =mrdescription;
		}
	}
	
	/** 雙擊測試項目時的動作 **/
	function trDoubleClick(indSel,indCont,mrid) {
		
		isInDB = $("#"+mrid).attr("isInDB");	 //確認儲存點是在CDB or CXML
		$("#addReqMappingBut").attr("mrid",mrid);
		$("#requireLog tr").remove();
		$(".owner").attr("mrid",mrid);
		$(".owner").attr("sel",indSel);
		
		var sourceid = $("#"+mrid+" td:nth-child(2) input").val();
		$("#detail_sourceid").html(sourceid);
		
		/** 這裡的if 主要是將資料寫入UI **/
		if (isInDB == "true") {
			/** indCont記錄了 在CDB陣列中的index位置 **/
			indCont = $("#"+mrid).attr("Cont");
			$(".owner").attr("cont",indCont);
			
			$("#detail_mrdescription").html(CDB[indCont].mrdescription);
			
			erList(CDB[indCont].propose,"propose");
			erList(CDB[indCont].designer,"designer");
			erList(CDB[indCont].designpm,"designpm");
			erList(CDB[indCont].reference,"reference");
			
			var testerStr = "";
			var testerSet = $("#"+mrid+ " td:nth-child(4) li");
			if (testerSet != undefined) {
				$.each(testerSet,function(i){
					var nickName = $(this).attr("nickName");
					testerStr += nickName +",";
				});	
			}
			$("#detail_tester").html(testerStr);
			
			if (CDB[indCont].require != undefined) {
				var numRequireLog = CDB[indCont].require.length; 
				for(i=0;i<numRequireLog;i++) {
					var ind = (i+1) ;
					var bgcolor=getbgColor(ind);
					$("#requireLog").append("<tr bgcolor="+bgcolor+" id=\""+ind+"_req\" ><td><button onClick=\"Click_removeReqMapping(this)\" ind=\""+ind+"\" type=\"button\">－</button></td><td>"+ind+"</td><td><input id=\""+mrid+"_requireID_"+ind+"\" value=\""+CDB[indCont].require[i].requireID+"\" size=\"10\" type=\"text\"/></td><td><input id=\""+mrid+"_swdsID_"+ind+"\" value=\""+CDB[indCont].require[i].swdsID+"\" size=\"10\" type=\"text\"/></td><td><input id=\""+mrid+"_sitrID_"+ind+"\" value=\""+CDB[indCont].require[i].sitrID+"\" size=\"10\" type=\"text\"/></td></tr>");	
				}
			}
		} else {
			/** 僅顯示，不可修改 **/
			$("#detail_mrdescription").html(CXML[indSel].cont[indCont].mrdescription);
			
			$(".owner").attr("cont",indCont);
			
			erList(CXML[indSel].cont[indCont].propose,"propose");
			erList(CXML[indSel].cont[indCont].designer,"designer");
			erList(CXML[indSel].cont[indCont].tester,"tester");
			erList(CXML[indSel].cont[indCont].reference,"reference");
			erList(CXML[indSel].cont[indCont].designpm,"designpm");
			
			if (CXML[indSel].cont[indCont].require != undefined) {
				var numRequireLog = CXML[indSel].cont[indCont].require.length;
				for(i=0;i<numRequireLog;i++) {
					var ind = (numRequireLog +1) ;
					var bgcolor=getbgColor(ind);
					$("#requireLog").append("<tr bgcolor="+bgcolor+" id=\""+ind+"_req\" ><td><button onClick=\"Click_removeReqMapping(this)\" ind=\""+ind+"\" type=\"button\">－</button></td><td>"+(i+1)+"</td><td><input id=\""+mrid+"_requireID_"+(i+1)+"\" value=\""+CXML[indSel].cont[indCont].require[i].requireID+"\" size=\"10\" type=\"text\"/></td><td><input id=\""+mrid+"_swdsID_"+(i+1)+"\" value=\""+CXML[indSel].cont[indCont].require[i].swdsID+"\" size=\"10\" type=\"text\"/></td><td><input id=\""+mrid+"_sitrID_"+(i+1)+"\" value=\""+CXML[indSel].cont[indCont].require[i].sitrID+"\" size=\"10\" type=\"text\"/></td></tr>");	
				}
			}
		}
		
		
		setAttr("module",indSel,indCont,isInDB);
		setAttr("yymm",indSel,indCont,isInDB);
		setAttr("createdate",indSel,indCont,isInDB);
		setAttr("onlinedate",indSel,indCont,isInDB);
		setAttr("desc",indSel,indCont,isInDB);
		setAttr("process",indSel,indCont,isInDB);
		$("#testItemDetail").css("visibility", "visible");

		$("#testItemDetail").dialog( {
			resizable : true,
			width : 850,
			height : 600,
			modal : true,
			buttons : {
				"關閉" : function() {
					/** 現在要將UI的內容回寫至 資料結構中 **/
					var requireTMP;
					if ($("#requireLog tr").size()>0){
						var requires = [];
						for (t=0;t<$("#requireLog tr").size();t++) {
							var tmpp = "#"+mrid+"_requireID_"+ (t+1);
							var req = $(tmpp)[0].value;
							tmpp = "#"+mrid+"_swdsID_"+ (t+1);
							var swds = $(tmpp)[0].value;
							tmpp = "#"+mrid+"_sitrID_"+ (t+1);
							var sitr = $(tmpp)[0].value;
							if ($.trim(req)!="" || $.trim(swds)!="" || $.trim(sitr)!="") {
								requireTMP = {requireID:req,swdsID:swds,sitrID:sitr};
								requires.push(requireTMP);		
							}
						}
						
						if (isInDB == "true") {
							CDB[indCont]["require"] = requires;
						} else {
							CXML[indSel].cont[indCont]["require"] = requires;	
						}
					}
					
					if (isInDB == "true") {
						CDB[indCont].createdate = $("#detail_createdate")[0].value;
						CDB[indCont].onlinedate = $("#detail_onlinedate")[0].value;
						CDB[indCont].desc = $("#detail_desc")[0].value;
						CDB[indCont].module = $("#detail_module")[0].value;
						CDB[indCont].process = $("#detail_process")[0].value;
						CDB[indCont].yymm = $("#detail_yymm")[0].value;
						SavaBackToDataStructure(indSel,indCont,"propose",true);
						SavaBackToDataStructure(indSel,indCont,"designer",true);
						SavaBackToDataStructure(indSel,indCont,"designpm",true);
					} else {
						CXML[indSel].cont[indCont].createdate = $("#detail_createdate")[0].value; 
						CXML[indSel].cont[indCont].onlinedate = $("#detail_onlinedate")[0].value;
						CXML[indSel].cont[indCont].desc = $("#detail_desc")[0].value;
						CXML[indSel].cont[indCont].module = $("#detail_module")[0].value;
						CXML[indSel].cont[indCont].process = $("#detail_process")[0].value;
						CXML[indSel].cont[indCont].yymm = $("#detail_yymm")[0].value;
						SavaBackToDataStructure(indSel,indCont,"propose",false);
						SavaBackToDataStructure(indSel,indCont,"designer",false);
						SavaBackToDataStructure(indSel,indCont,"designpm",false);
					}
					
					
					$(this).dialog("close");
				}
			}
		});		
	}
	
	/** 上一步 **/
	function Click_prevStep(){
		$("#tpBody").css("visibility", "hidden");
		$("#tpComment").removeAttr("disabled");
		$("#testPlanName").removeAttr("disabled");
		$("#nextStep").css("visibility", "visible");
		$("#tdTPOwner").removeAttr("disabled");
		CXML = [{id:77777,cont:[]}];
	}
	
	/** 下一步 **/
	function Click_nextStep(){
		/**
			1. 檢查必要欄位有無輸入
			2. 把畫面上的測試項目全部清空
			3. 自DB中讀取存取的測試項目塞入
		**/
		var str = $("#testPlanName").val();
		$("#hidden_testPlanName")[0].value = str;
		if ($.trim(str)=="") {
			alert("計畫案名稱不得為空");						
		} else {
			var tpoStr = "";
			$(".selectdTPOwner").each(function() {
				var tpOwnerID = $(this).attr("id");
				tpoStr += tpOwnerID +","; 
			});	
			
			/** 將選取的人員，加到q_form的欄位 **/
			if (tpoStr.length != 0){
				$("#sub_tpOwnerList")[0].value = tpoStr;
			}
			
			/** 放到q_form裡才能送到後頭去 **/
			$("#sub_tpid").val( $("#testPlanSN").val() );			//測試案ID
			$("#sub_tpName")[0].value = $("#testPlanName").val();	//測試案名稱
			/** 測試案負責人，在選取時，就完成賦值 **/
			$("#sub_tpComment")[0].value = $("#tpComment").val();	//測試案註解
			var TPUD = $("#TPUD")[0].value;
			$("#sub_tpcud")[0].value = TPUD;								//測試案建立日期&最後修改日期
			
			/** 建立新的測試計畫案 **/
			$.ajax({														
				type : "post",
				url : "CreateTP",
				data : $("#q_form").serializeArray(),
				dataType : "TEXT",
				success : function(queryResult) {
					if (queryResult != TPUD) {
						$("#TPUD")[0].value = queryResult;
					}
					
					$("#mainTbody tr").remove();	
					var nn = "";
					
					/** 自DB取得測試計畫案所擁有的測試項目 **/
					$.ajax({														
						type : "post",
						url : "GetMRItems",
						data : $("#q_form").serializeArray(),
						dataType : "JSON",
						success : function(queryResult) {
							var i=999;
							var m=0;
							$("#sub_ver")[0].value = queryResult.ver;
							if (queryResult.size > 0) {
								$.each(queryResult.sqlData, function(a, res) {
									var mrid = res.mrid;
									var sourceid = res.sourceid;
									var mrdescription = res.mrdescription;
									var ver = res.ver;
									var isExistNotInCDB = true;
									var tpName = $("#hidden_testPlanName")[0].value;
									
									for (r=0;r<CDB.length;r++) {
										if (CDB[r].mird == mrid) {
											isExistNotInCDB = false;
										}
									}
									if (isExistNotInCDB) {
										CDB.push(res);
									}
									var CDBLength = CDB.length;
									
									var tester = "";
									if (res.tester != undefined) {
										$.each(res.tester,function(indexTester,user) {
											tester += "<li class=\"mrTestOwner\" nickName=\""+user.nickName+"\" val=\""+user.userID+"\">"+user.nickName+"</li>";
										});	
									}
									
									var ind = $("#mainTbody tr").length+1;
									var bgcolor=getbgColor(ind);
									/** 若是自行建立的項目，不能有fromImport的Class **/
									var fromImportStr ="";
									if (res.isImportAble) {
										fromImportStr = "fromImport";
									}
									
									$("#mainTbody").append("<tr id=\""+mrid+"\" sel=\""+i+"\" cont=\""+a+"\" isInDB=\"true\" class=\"inDB\" ondblclick=\"trDoubleClick('"+i+"','"+(a+1)+"','"+mrid+"')\" bgcolor="+bgcolor+"><td>"+ind+"</td><td><input type=\"text\" size=\"21\" value=\""+sourceid+"\" sel=\""+i+"\" cont=\""+m+"\" onkeyup=\"saveBack01('"+i+"','"+a+"','"+mrid+"')\" attr=\"sourceid\" mrid=\""+mrid+"\" /></td><td><textarea id='"+mrid+"_mrDesc' sel=\""+i+"\" cont=\""+m+"\" attr=\"mrdescription\" onkeyup=\"saveBack01('"+i+"','"+a+"','"+mrid+"')\" mrid=\""+mrid+"\" >"+mrdescription+"</textarea></td><td><ul id=\""+mrid+"_mrTester\">"+tester+"</ul></td><td>"+df(1)+"</td><td id=\"lupt_"+mrid+"\">"+df(1)+"</td><td width=\"235\"><button id='"+mrid+"_selTC' mrid=\""+mrid+"\" class='selTC' onClick=\"Click_selTC(this)\" type=\"button\" DISABLED>選擇案例</button><button id='"+mrid+"_fillTR' mrid=\""+mrid+"\" ver=\""+ver+"\" class='fillTR' onClick=\"Click_fillTR(this)\" type=\"button\" DISABLED>登打結果</button><button id='"+mrid+"_refItem' mrid=\""+mrid+"\" class='refItem "+fromImportStr+"' yymm=\""+res.yymm+"\" sel=\""+i+"\" cont=\""+a+"\" onClick=\"Click_refItem(this)\" type=\"button\" DISABLED>重新匯入</button><br/><button id='"+mrid+"_subTC' mrid=\""+mrid+"\" class='subTC' onClick=\"Click_subTC(this)\" type=\"button\" DISABLED>送審案例</button><button id='"+mrid+"_subTR' mrid=\""+mrid+"\" class='subTR' onClick=\"Click_subTR(this)\" type=\"button\" DISABLED>送審結果</button><button id='"+mrid+"_infoItem' mrid=\""+mrid+"\" tpname=\""+tpName+"\" class='infoItem' onClick=\"Click_infoItem(this)\" type=\"button\" DISABLED>相關資訊</button></td></tr>");
									
									if (res.isImportAble) {
										$("#"+mrid+"_refItem").removeAttr("disabled"); 
									}
									
									if (res.isTCsubmitAble){
										$("#"+mrid+"_subTC").removeAttr("disabled");
										$("#"+mrid+"_fillTR").removeAttr("disabled");
										checkIsSubmitTRable(mrid,ver);
									}
									if (res.isTRsubmitAble) { $("#"+mrid+"_subTR").removeAttr("disabled"); }
									
									$("#"+mrid+"_infoItem").removeAttr("disabled");
									$("#"+mrid+"_selTC").removeAttr("disabled");
								});
								
								/** 如果有找到測試項目，就可以按下儲存 **/
								$("#saveTPBody").removeAttr("disabled");
							} else {
								/** 找不到測試項目，不可按下儲存 **/
								$("#saveTPBody").attr("disabled","disabled");			
							}
						}
					});
					
					$("#tpBody").css("visibility", "visible");
					$("#tpComment").attr("disabled","disabled");
					$("#testPlanName").attr("disabled","disabled");
					$("#nextStep").css("visibility", "hidden");
					$("#tdTPOwner").attr("disabled","disabled");
				}
			});
		}
	}
	
	$(document).ready(
		function() {
			if (typeof (JSON) == 'undefined') { //沒有 JSON 時才讓 browser 下載 json2.js
				$('head').append($("<script type='text/javascript' src='js/json2.js'>"));
			}
			
			var dt = new Date();
			
			$("#loginUser")[0].value = $.cookie("userID");
			var tpStatus = $.cookie("currStatus");
			$("#snType").val("tp");
			$(".dialog").css("visibility", "hidden");
			$("#sub_submittedBy").val("tester");	//為了使同一支程式，能交分辨提交人員的角色
			
			
			var tpsn = "";
			
			if (tpStatus == null || tpStatus != "updateTP") {
				$.ajax({	//取得測試計劃案目前的流水號
					type : "post",
					url : "GetSN",
					data : $("#q_form").serializeArray(),
					dataType : "text",
					success : function(queryResult) {
						tpsn = df(2) + queryResult;
						$("#testPlanSN").attr("value", tpsn);
						$("#sub_tpid").val( $("#testPlanSN").val());		//測試案ID
					}
				});
				var createdDate = df(3);
				$("#TPCD").attr("value", createdDate );
				$("#TPUD").attr("value", createdDate );			
			} else {
				$.cookie("currStatus", null);
				$("#testPlanSN").attr("value", $.cookie("tpid") );
				$("#sub_tpid").val( $("#testPlanSN").val());		//測試案ID
				/** 去把指定TP的內容抓回來 **/
				$.ajax({
					type : "post",
					url : "GetTP",
					data : $("#q_form").serializeArray(),
					dataType : "JSON",
					success : function(qr) {
						$.each(qr.sqlData, function(i, res) {
							var tpName = res.tpName;
							var cDate = res.screateDate;
							var uDate = res.slastUpdateDate;
							var comm =res.comment;
							$("#testPlanName").attr("value",tpName);
							$("#TPCD").attr("value",cDate);
							$("#TPUD").attr("value",uDate);
							$("#tpComment")[0].value = comm;
							$.each(res.tpOwner, function(i, owner) {
								$("#tpOwner").append("<li class=\"selectdTPOwner\" val=\""+owner.nickName+"\" id="+owner.userID+">"+owner.nickName+"</li>");
							});
						});
						
					},error : function(xhr, ajaxOptions, thrownError) {
						alert("出代誌啊!! \n\n"+xhr.status+"\n\n"+xhr.responseText);
					}
				});
			}
			/** 趁一開始，將測試結果的種類抓回來 **/
			$.ajax({
				type : "post",
				url : "GetTRresultType",
				dataType : "JSON",
				success : function(TRType) {
					$.each(TRType.sqlData, function(i, res) {
						trType.push(res);
					});
				},error : function(xhr, ajaxOptions, thrownError) {
					alert("出代誌啊!! \n\n"+xhr.status+"\n\n"+xhr.responseText);
				}
			});
			
		});
</script>
</head>
<body>
	<br />
	<div>
	<table>
		<tr>
			<th>計畫編號</th>
			<th><font face="標準體" color="#FF0000"><sub>*</sub></font>計畫名稱</th>
			<th colspan="2">計畫案負責人</th>
			<th>建立日期</th>
			<th>最後修改日期</th>
		</tr>
		<tr>
			<td><input id="testPlanSN" name="testPlanSN" type="text" disabled="disabled" size="10"/></td>
			<td><input id="testPlanName" name="testPlanName" type="text" /></td>
			<td><button type="button" id="tdTPOwner" onClick="pickTPOwner('tpOwner')">選擇</button></td>
			<td><ul id="tpOwner"></ul></td>
			<td><input id="TPCD" name="TPCD" type="text" disabled="disabled" size="18" /></td>
			<td><input id="TPUD" name="TPUD" type="text" disabled="disabled" size="18" /></td>
		</tr>
		<tr>
			<td colspan="6"><br/>備註：</td>
		</tr>
		<tr>
			<td colspan="6"><textarea id="tpComment" cols="73" rows="5" ></textarea></td>
		</tr>
		<tr>
			<td colspan="6" id="TDstepCtrl"><button id="nextStep" onClick="Click_nextStep()" type="button">下一步</button></td>
		</tr>
	</table>
	</div>
		<p>
	<div id="tpBody" class="dialog">
	<table>
		<thead>
			<tr><td colspan="7">
				維護測試項目&nbsp;
				<button id="importMR" onClick="Click_importMR()" type="button">匯入MR月需求</button>&nbsp;
				<button id="createMRItem" type="button" onClick="createMRItem()">建立項目</button>
			</td></tr>
			
			<tr>
				<th>#</th>
				<th width="230">項目編號</th>
				<th><font face="標準體" color="#FF0000"><sub>*</sub></font>項目名稱</th>
				<th>測試負責人</th>
				<th>建立日期</th>
				<th>最後修改日期</th>
				<th>&nbsp;</th>
			</tr>
		</thead>
		
		<tbody id="mainTbody">
		</tbody>
		
		<tfoot>
			<tr>
				<td id="TDprevStep" colspan="3"><button id="prevStep" onClick="Click_prevStep()" type="button">上一步</button></td>
				<td id="TDsaveTPBody" colspan="4"><button id="saveTPBody" type="button" onClick="Click_saveMRItem();" >儲存</button></td>
			</tr>
		</tfoot>
	</table>
	</div>
	<div id="dialog-mrLevel_00" title="匯入MR需求" class="dialog">
		<table id="mrLevel_00">
			<thead>
				<tr>
					<th></th>
					<th>#</th>
					<th colspan="2">MR 月份</th>
				</tr>
			</thead>
			
			<tbody id="mrLevel_00_body">
			</tbody>
		</table>
	</div>
	<p>
	<div id="dialog-mrLevel_01" title="勾選欲匯入的月需求" class="dialog">
		<select id="mrSel" disabled>
		</select>
		<table id="mrLevel_01">
			<thead>
				<tr>
					<th><input type="checkbox" id="isImportCheckALL"  onClick="chkALL('isImport')" /></th>
					<th>#</th>
					<th>MR Description</th>
				</tr>
			</thead>
			
			<tbody id="mrLevel_01_body">
			</tbody>
		</table>
	</div>

	<!-- 連按兩下出現的表格 -->	
	<div id="testItemDetail" title="測試項目屬性" class="dialog">
		 <table>
			<tr>
				<th class="itemDetail">sourceid:&nbsp;</th><td><div id="detail_sourceid" ></div></td><th class="itemDetail">designer:&nbsp;</th><td><ul id="detail_designer"></ul><button onClick="Click_changeOwner(this)" sel="" cont="" mrid="" tar="detail_designer" class="owner" type="button">選擇</button></td>
			</tr>
			<tr>
				<th class="itemDetail">propose:</th><td><ul id="detail_propose"></ul><button onClick="Click_changeOwner(this)" tar="detail_propose" sel="" cont="" mrid="" class="owner" type="button">選擇</button><th class="itemDetail">設計PM:&nbsp;</th><td><ul id="detail_designpm"></ul><button onClick="Click_changeOwner(this)" tar="detail_designpm" sel="" cont="" mrid="" class="owner" type="button">選擇</button></td>
			</tr>
			<tr>
				<th class="itemDetail"><font face="標準體" color="#FF0000"><sub>*</sub></font>mrdescription:&nbsp;</th><td><div id="detail_mrdescription"></div></td><th class="itemDetail"><font face="標準體" color="#FF0000"><sub>*</sub></font>yymm:&nbsp;</th><td><input sel="" cont="" attr="yymm" class="req_2" id="detail_yymm" type="text" /></td>
			</tr>
			<tr>
				<th class="itemDetail"><font face="標準體" color="#FF0000"><sub>*</sub></font>createdate:&nbsp;</th><td><input  sel="" cont="" attr="createdate" class="req_2" id="detail_createdate" type="text" /></td><th class="itemDetail"><font face="標準體" color="#FF0000"><sub>*</sub></font>onlinedate:&nbsp;</th><td><input  sel="" cont="" attr="onlinedate" class="req_2" id="detail_onlinedate" type="text" /></td>
			</tr>
			<tr>
				<th class="itemDetail">tester:&nbsp;</th><td><div id="detail_tester"></div></td><th class="itemDetail">module:&nbsp;</th><td><input  sel="" cont="" attr="module" id="detail_module" type="text" /></td>
			</tr>
			<tr>
				<th class="itemDetail">desc:&nbsp;</th><td><input  sel="" cont="" attr="desc" id="detail_desc" type="text" /></td><th class="itemDetail">process:&nbsp;</th><td><input  sel="" cont="" attr="process" id="detail_process" type="text" /></td>
			</tr>
			<tr>
				<th class="itemDetail">reference:&nbsp;</th><td><ul id="detail_reference"></ul></td><th class="itemDetail">分析文件:&nbsp;</th><td><input  sel="" cont="" attr="ad" id="detail_ad" type="text" /></td>
			</tr>
			<tr>
				<th class="itemDetail">測試案例:&nbsp;</th><td><input  sel="" cont="" attr="tc" id="detail_tc" type="text" /></td><th class="itemDetail">programmer:&nbsp;</th><td><input  sel="" cont="" attr="programmer" id="detail_programmer" type="text" /></td>
			</tr>
		</table>
		<p>
		<p>
		<p>
		<p>
		<p>
		<p>
		<table>
			<thead>
				<tr>
					<th><button type="button" mrid="" id="addReqMappingBut" onClick="Click_addReqMapping(this)">＋</button></th>
					<th>#</th>
					<th>需求文件編號</th>
					<th>SWDS對應編號</th>
					<th>SITR對應編號</th>
				</tr>		
			</thead>
			<tbody id="requireLog">
			</tbody>
		</table>
	</div>
	
	<div id="dialog-Group" class="dialog" title="請勾選人員">
		<table>
			<thead>
				<tr>
					<th><input type="checkbox" id="tpoCheckALL" onClick="chkALL('tpo')"/></th>
					<th>#</th>
					<th>人員列表</th>
				</tr>
			</thead>
			<tbody id="tBodyTPOwner">
			</tbody>
		</table>
	</div>
	
	<div id="dialog-saveMRItemTCmapping" title="儲存案例">
		<div id="confirmMessage"></div>
	</div>
	
	
	<div id="dialog-selTC" title="查詢測試案例" class="dialog" >
		<table>
			<thead>
				<tr>
					<td colspan="4"><button type="button" onClick="Click_CreateTC()">新建測試案例</button></td>
				</tr>
				<tr>
					<th colspan="2" class="query">測試案例名稱</th>
					<td colspan="2" width="50%" class="query"><input type="text" id="q_tcName" class="require_from_group"/></td>
				</tr>
				<tr>
					<th colspan="2" class="query">測試識別代號</th>
					<td colspan="2" width="50%" class="query"><input type="text" id="q_tcID" class="require_from_group"/></td>
				</tr>
				<tr>
					<th colspan="2" class="query">驗證重點</th>
					<td colspan="2" width="50%" class="query"><input type="text" class="require_from_group"/></td>
				</tr>
				<tr>
					<th colspan="2" class="query">測試資料</th>
					<td colspan="2" width="50%" class="query"><input type="text" class="require_from_group"/></td>
				</tr>
				<tr>
					<th colspan="2" class="query">測試流程</th>
					<td colspan="2" width="50%" class="query"><input type="text" class="require_from_group"/></td>
				</tr>
				<tr>
					<th colspan="2" class="query">預期結果</th>
					<td colspan="2" width="50%" class="query"><input type="text" class="require_from_group"/></td>
				</tr>
				<tr>
					<td colspan="2" class="query"><button id="saveTCselected" mrid="" onClick="Click_saveTC()" type="button">儲存</button></td>
					<td colspan="2" class="function"><button onClick="Click_queryTC()" type="button">送出查詢</button><button type="button">重設</button></td>
				</tr>
				<tr><td colspan="4">&nbsp;</td></tr>
				<tr><td id="q_message" colspan="4">&nbsp;</td></tr>
				<tr>
					<th colspan="4">已選擇案例</th>
				</tr>
				<tr>
					<th width="10%">#</th>
					<th>案例ID</th>
					<th>案例名稱</th>
					<th width="15%">&nbsp;</th>
				</tr>
			</thead>
			
			<tbody id="selectedTCBody">
			</tbody>
			
			<tfoot>
				<tr><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>
			</tfoot>
		</table>
		<p/>
		<p/>
		<div id="queryTCDiv" class="dialog" >
		<h2 id="ReaultNum"></h2>
		<table>
			<thead>
				<tr>
					<th>#</th>
					<th>測試案例ID</th>
					<th>測試案例</th>
					<th>&nbsp;</th>
				</tr>
			</thead>
			<tbody id="queryTCBody">
			</tbody>
		</table>
		</div>
		
	</div>
	
	<div id="errorMessage"></div>
	<input type="hidden" id="tpStatus" />
	<form id="q_form" method="post">
		<input type="hidden" id="fileName" name="fileName" />
		<input type="hidden" id="snType" name="snType" />
		<input type="hidden" id="sub_tpid" name="tpid" />						<!-- 測試案ID -->
		<input type="hidden" id="sub_mrid" name="mrid" />						<!-- 測試項目ID -->
		<input type="hidden" id="sub_tpName" name="tpName" />					<!-- 測試案名稱 -->
		<input type="hidden" id="sub_tpOwnerList" name="tpOwnerList" />			<!-- 測試案負責人 -->
		<input type="hidden" id="sub_mrTesterList" name="mrTesterList" />		<!-- 測試案例負責人 -->
		<input type="hidden" id="sub_tpComment" name="tpComment" />				<!-- 測試案註解 -->
		<input type="hidden" id="sub_tpcud" name="tpcud" />						<!-- 測試案建立日期&最後修改日期 -->
		<input type="hidden" id="sub_CDB" name="sub_CDB" />
		<input type="hidden" id="sub_selectTCList" name="selectTCList" />		<!-- 選擇的測試案例JSON物件 -->
		<input type="hidden" id="sub_submitorComment" name="submitorComment" />	<!-- 選擇的測試案例JSON物件 -->
		<input type="hidden" id="sub_ver" name="ver" />							<!-- 目前測試項目選擇案例的版次 -->
		<input type="hidden" id="sub_yymm" name="yymm" />
		<input type="hidden" id="loginUser" name="loginUser" />					<!-- 目前登入的使用者 -->
		<input type="hidden" id="sub_submittedBy" name="submittedBy" />			<!-- 送出的角色為 --> 
		<input type="hidden" id="sub_er" name="er" />							<!-- 要查詢的後端角色為 -->
		
		<!-- 測試結果的登打 -->
		<input type="hidden" id="sub_tr_retest" name="tr_retest" />
		<input type="hidden" id="sub_tr_Succ" name="tr_Succ" />
		<input type="hidden" id="sub_tr_Fail" name="tr_Fail" />
		<input type="hidden" id="sub_tr_Cant" name="tr_Cant" />
		<input type="hidden" id="sub_trSN" name="trSN" />
		<input type="hidden" id="sub_edition" name="edition" />
		<input type="hidden" id="sub_tcuid" name="tcuid" />
		<input type="hidden" id="sub_numKeyPoint" name="numKeyPoint" />
	</form>
	
	<div id="dialog-subTC" title="確認送審項目" class="dialog">
	<table>
		<tbody id="ConfirmSubTC">
		</tbody>
		
		<tfoot>
			<tr></tr>
			<tr><th class="left" colspan="2">送審人員意見</th><td rowspan="2" colspan="2"></td></tr>
			<tr><td colspan="2"><textarea id="tcSubmitComment" cols="60"></textarea></td></tr>
		</tfoot>
	</table>
	</div>
	
	<div id="dialog-fillTR" title="登打測試結果" class="dialog" >
	<table>
		<thead>
			<tr><th colspan="2" class="query">測試識別代號：</th><td id="tr_uid" class="query"  colspan="2" ></td></tr>
			<tr><th colspan="2" class="query">測試案例名稱：</th><td id="tr_tcName" class="query" colspan="2" ></td></tr>
			<tr><th colspan="2" class="query"><font color="#FF0000"><sub>*</sub></font>系統版本：</th><td colspan="2" ><input id="tr_edition" class="fillInTR" type="text" /></td></tr>
			<tr>
				<th colspan="2" class="query">測試結果：</th>
				<td colspan="2" class="query"><select id="trStatus" class="fillInTR" onchange="trStatusChange(this)"></select></td>
			</tr>
		</thead>
		<tbody>
			<tr><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>
			<tr><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>
			
			<tr><th colspan="2">驗證重點</th><th colspan="2">測試資料</th><th colspan="2">測試程序</th><th colspan="2">預期結果</th></tr>
			<tr>
				<td colspan="2" id="tr_tcKeyPoint"></td>
				<td colspan="2" id="tr_tcTestData"></td>
				<td colspan="2" id="tr_tcProcess"></td>
				<td colspan="2" id="tr_tcResExp"></td>
			</tr>
			<tr><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>
			<tr><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>
		</tbody>
		<tfoot>
			<tr><th>重驗<br/>次數</th><th>驗證<br/>重點數</th><th>成功數</th><th>失敗數</th><th>無法<br/>測試數</th><th colspan="3" >待測<br/>試數</th></tr>
			<tr><td><input id="tr_retest" class="fillInTR" type="text" size="1" tcuid="" onkeyup='return ValidateNumber(this,value,true)' /></td><td><input id="tr_NumKeyPoint" type="text" size="1" disabled /></td><td><input id="tr_Succ" class="fillInTR" type="text" size="1" tcuid="" onkeyup="return ValidateNumber(this,value,true)" /></td><td><input id="tr_Fail" class="fillInTR" type="text" size="1" tcuid="" onkeyup="return ValidateNumber(this,value,true)" /></td><td><input id="tr_Cant" class="fillInTR" type="text" size="1" tcuid="" onkeyup="return ValidateNumber(this,value,true)" /></td><td colspan="3" class="fillInTR" id="tr_Wait">&nbsp;</td></tr>
		</tfoot>
			
	</table>
	</div>
	
	<div id="dialog-TRlevel_01" class="dialog" >
	<table>
		<thead>
			<tr><th class="query" width="13%" >測試項目：</th><td id="TRlecel_01_mrDesc" colspan="11"></td></tr>
			<tr><td>&nbsp;</td><td>&nbsp;</td></tr>
			<tr>
				<th class="center fillCol">障礙登打</th>
				<th class="center">#</th>
				<th class="center">測試案例<br/>名稱</th>
				<th class="center">驗證重點</th>
				<th class="center">預期結果</th>
				<th class="center">測試結果</th>
				<th class="center">缺失數</th>
				<th class="center">驗證<br/>重點數</th>
				<th class="center">成功數</th>
				<th class="center">失敗數</th>
				<th class="center">無法測試數</th>
				<th class="center">待測數</th>
			</tr>
		</thead>
		<tbody id="TRlevel_01_body">
		</tbody>
	</table>
	</div>
	
	<div id="dialog-subTR" class="dialog" >
	<table>
		<tbody id="ConfirmSubTR">
		<tr><th colspan="2">確定送審</th></tr>
		<tr><td colspan="2" id="subTR_mrdesciption"></td></tr>
		
		<tr><td colspan="2">&nbsp;</td></tr>

		
		<tr><td colspan="2">&nbsp;</td></tr>
		<tr><th width="50%">上傳附加檔案</th><th width="50%">簽核意見</th></tr>
		<tr><td>
			<form id="form_TRFileUpload" method="post" enctype="multipart/form-data" target="FileUpload" action="FileUpload">
				<input name="file" id="file" size="27" type="file" class="multi" /><br />
				<input type="hidden" id="loginUserFileUpload" name="loginUser" />					<!-- 目前登入的使用者 -->
				<input type="hidden" id="sub_tpidFileUpload" name="tpid" />						<!-- 測試案ID -->
				<input type="hidden" id="sub_mridFileUpload" name="mrid" />						<!-- 測試項目ID -->
				<iframe id="FileUpload" name="FileUpload" src="" style="width:0;height:0;border:0px solid #fff;"></iframe>
			</form>
		</td>
			
			<td><textarea id="trSubmitComment" cols="8" rows="2" ></textarea></td></tr>
		
		</tbody>
	</table>
	</div>
	
	<div id="dialog-delMR" class="dialog" >
	<table>
		<tbody id="ConfirmDelTR">
		<tr><th colspan="2">確定刪除</th></tr>
		<tr><td colspan="2" id="delMR_mrdesciption"></td></tr>
		</tbody>
	</table>
	</div>
	
	
	<!-- 相關資訊的跳出視窗 -->
	<div id="dialog-infoMR" title="相關資訊" class="dialog" >
		<div>
		<button type="button" id="but_assignTester" onClick="Click_assignTestor()">指派人員</button>
		<button type="button" id="but_delMRItem" mrid="" onClick="Click_deleteMRitem(this)">刪除項目</button>
		
		<script type="text/javascript">
		$("#but_assignTester").button();
		$("#but_delMRItem").button();
		</script>
		
		<p>
		<p>
		
		<table>
		<tr><th width="50%">上傳附加檔案</th><th width="50%">簽核意見</th></tr>
		<tr><td>
			<form id="form_infoFileUpload" method="post" enctype="multipart/form-data" target="FileUpload" action="FileUpload">
				<input name="file" id="file2" size="27" type="file" class="multi" />
				<input type="hidden" id="infoLoginUserFileUpload" name="loginUser" />					<!-- 目前登入的使用者 -->
				<input type="hidden" id="infoTpidFileUpload" name="tpid" />						<!-- 測試案ID -->
				<input type="hidden" id="infoMridFileUpload" name="mrid" />						<!-- 測試項目ID -->
				<iframe id="FileUpload" name="FileUpload" src="" style="width:0;height:0;border:0px solid #fff;"></iframe>
			</form>
			<br/>
		<button onClick="Click_infoFileUpload()" type="button">上傳檔案</button>
		</td>
		<td>
		<form id="form_infoComment" method="post">
			<textarea id="textarea_infoComment">
			</textarea>
		</form>
		<br/><button onClick="Click_infoComment()" type="button">送出意見</button>
		
		</td>
		</tr>
		</table>
		
		<p>
		<p>
		<table width="100%">
			<tr><th class="query">計畫案</th><td colspan="5" id="info_tpName">&nbsp;</td></tr>
			<tr><th class="query">測試項目</th><td colspan="5" id="info_mrDesc">&nbsp;</td></tr>
			<tr><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>
			<tr><th class="query">指派人員</th><td class="query" id="info_assignedTester"><ul id="mrTester"></ul></td></tr>
			<tr>
				<th class="query">指定案例</th><td id="info_assignedTC"><ul id="mrTC"></ul></td>
				<th class="query">送審案例</th><td id="info_subTC">&nbsp;</td>
				<th class="query">測試案例審核</th><td id="info_reviewTC">&nbsp;</td>
			</tr>
			<tr> 
				<th class="query">結果更新</th><td id="info_fillTR">&nbsp;</td>
				<th class="query">送審結果</th><td id="info_subTR">&nbsp;</td>
				<th class="query">測試結果審核</th><td id="info_reviewTR">&nbsp;</td>
			</tr>
		</table>
	
		<div id="infoAction"></div>
		<div id="infoComment"></div>
		<div id="infoFileUpload"></div>
		</div>
		
	</div>
	<form id="form_fileDoload" method="post" target="FileDownload" action="FileDownload">
		<input type="hidden" id="sub_sn" name="sn" />			
		<iframe id="FileDownload" name="FileDownload" src="" style="width:0;height:0;border:0px solid #fff;"></iframe>
	</form>
	<input type="hidden" id="hidden_testPlanName"/>
</html>